import request from '@/utils/request'
import { camelCaseObject } from '@/libs/object'

const AUTH_PREFIX_V1 = `/api/v1/cmdb`

export function getCmdbAssetList(params) {
  return request.get(`${AUTH_PREFIX_V1}/assets`, { params }).then(res => camelCaseObject(res))
}

export function getCmdbAssetListByPage(params) {
  return request.get(`${AUTH_PREFIX_V1}/assets/page`, { params }).then(res => camelCaseObject(res))
}

export function getCmdbAsset(assetId) {
  return request.get(`${AUTH_PREFIX_V1}/assets/${assetId}`).then(res => camelCaseObject(res))
}

export function createCmdbAsset(params) {
  return request.post(`${AUTH_PREFIX_V1}/assets`, params).then(res => camelCaseObject(res))
}

export function updateCmdbAsset(assetId, params) {
  return request.put(`${AUTH_PREFIX_V1}/assets/${assetId}`, params).then(res => camelCaseObject(res))
}

export function deleteCmdbAsset(assetId) {
  return request.delete(`${AUTH_PREFIX_V1}/assets/${assetId}`).then(res => camelCaseObject(res))
}

export function pingAliveCheckAsset(assetId) {
  return request.put(`${AUTH_PREFIX_V1}/assets/${assetId}/ping_check`).then(res => camelCaseObject(res))
}
